package com.xiaolei.MmkvKtx

import android.content.Context
import com.tencent.mmkv.MMKV
import java.io.File

object MMKVExt
{
    var mmkv: MMKV? = null
    @Synchronized
    fun <T : Context> getMMKV(context: T): MMKV
    {
        if (mmkv == null)
        {
            val mmkvDir = File(context.cacheDir, "${context.packageName}.MMKV")
            if (!mmkvDir.exists())
            {
                mmkvDir.mkdirs()
            }
            MMKV.initialize(mmkvDir.absolutePath)
            mmkv = MMKV.defaultMMKV()
        }
        return mmkv!!
    }
}